package com.matrix.java.chap_06;

/*
    回文素数
 */
public class Ex6_26 {
    public static void main(String[] args) {
        int count = 1;
        int i = 2;
        do {
            if (isPrime(i) && isPalindrome(i)) {
                if (count % 10 != 0) {
                    System.out.print(i + "\t");
                } else {
                    System.out.println(i);
                }
                count++;
            }
            i++;
        } while (count < 100);
    }

    private static boolean isPrime(int num) {
        boolean isPrime = true;
        for (int i = 2; i < num; i++) {
            if (num % i == 0) {
                isPrime = false;
                break;
            }
        }
        return isPrime;
    }

    private static boolean isPalindrome(long num) {
        boolean isPalindrome = false;
        if (num == reverse(num)) {
            isPalindrome = true;
        }
        return isPalindrome;
    }

    private static long reverse(long num) {
        long reverse = 0;
        do {
            reverse = reverse * 10 + num % 10;
            num /= 10;
        } while (num != 0);
        return reverse;
    }
}
